package yxy.cherry.battle.module.affix.skill;

import yxy.cherry.battle.Battle;
import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.module.affix.AffixFactory;
import yxy.cherry.battle.module.affix.Skill;
import yxy.cherry.battle.module.affix.SkillType;
import yxy.cherry.battle.module.record.stream.RecordStream35HpDrain;
import yxy.cherry.battle.module.record.stream.RecordStreamGroup;
import yxy.cherry.battle.module.record.stream.RecordStream_SKL;
import yxy.cherry.data.bean.skill;

/**
 * @author James
 * 生命汲取（扣除目标最大生命值的X%，回复自己同等的生命值，扣除值的上限为自身生命值的X%）
 * @date 2022/2/25 18:30
 **/
@SkillType(Type = AffixFactory.SkillTypeEnum.生命汲取)
public class Affix24HpDrain extends Skill {
    public Affix24HpDrain(Fighter actor, skill skilldata, int probability, int[] params) {
        super(actor, skilldata, probability, params);
    }

    private int getReducePer() {return getParam(0);}
    private int getReducePerMax() {return getParam(1);}

    private RecordStreamGroup steamGroup;
    public RecordStreamGroup record(){
        steamGroup = getRecord().stream(new RecordStreamGroup());
        steamGroup.add(new RecordStream_SKL(getActor(), getSkillId()));
        return steamGroup;
    }

    @Override
    public boolean exec(Fighter actor, Fighter target) {
        if(!target.is活着()){
            Battle.battleLogger(7,"生命汲取：对手已死，吸不了血了！");
            return false;
        }
        long reduceHpMax = target.get生命() * getReducePer()/VALUE_比率分母;
        long selfHpAddMax = actor.get生命() * getReducePerMax()/VALUE_比率分母;
        long selfRealHpAdd = Math.min((actor.get生命()-actor.get血量()),selfHpAddMax);
        long realReduceHp = Math.min(selfRealHpAdd,reduceHpMax);

        long sActorHp = actor.get血量万分值();
        long sTargetHp = target.get血量万分值();

        actor.set治疗(realReduceHp);
        target.set伤害(realReduceHp);
        Battle.battleLogger(6,"生命汲取：施法者："+actor.getName()+"释放前生命万分值："+sActorHp+"当前万分值："+actor.get血量万分值()+"目标："+target.getName()+"血量原万分值："+sTargetHp+"被吸血后万分值："+target.get血量万分值()+"最大生命值："+target.get生命()+"扣除比例:"+getReducePer()+"施法者最大生命："+actor.get生命()+"扣除上限："+getReducePerMax()+"自己生命上限及缺血最小值:"+selfRealHpAdd+"最终减血量:"+realReduceHp);
        if (!target.is活着()) {
            target.handle本方有死将();
        }

        getRecord().get统计().getFighter(actor.getFighterPosition()).addDMG(realReduceHp);
        getRecord().get统计().getFighter(target.getFighterPosition()).addHUT(realReduceHp);
        getRecord().get统计().getFighter(actor.getFighterPosition()).addCUR(realReduceHp);

        steamGroup.add(new RecordStream35HpDrain(actor,target,realReduceHp,realReduceHp)).record();
        return true;
    }
}
